import { requestClient } from '#/api/request';

export namespace productApi {
  export interface productParams {
    id?: string;
    name: string;
    price: number | null;
    imageUrl: string;
  }
  export interface listItem {
    createTime: string;
    updateTime: string;
    id: string;
    name: string;
    price: number;
    state: number;
    startApptTime: string;
    endApptTime: string;
    imageUrl: string;
  }
  export interface getProductListResult {
    code: number;
    message: string;
    data: {
      total: string;
      list: listItem[];
    };
  }
  export interface getDetailResult {
    code: number;
    message: string;
    data: listItem;
  }
  export interface baseResult {
    code: number;
    message: string;
    data: string;
  }
  export interface addApptTimeSlotListParams {
    sunday: number;
    timeRangeList: { startTime: string; endTime: string }[];
  }
  export interface getAllApptTimeSlotListResultItem {
    id: string;
    sunday: number;
    apptTimeSlot: string;
  }
  export interface getAllApptTimeSlotListResult {
    code: number;
    message: string;
    data: getAllApptTimeSlotListResultItem[];
  }
}
/**
 * 添加商品
 */
export async function addProduct(data: productApi.productParams) {
  return requestClient.post<productApi.baseResult>(
    '/basic/product/addProduct',
    data,
  );
}

/**
 * 更新商品
 */
export async function updateProduct(data: productApi.productParams) {
  return requestClient.post<productApi.baseResult>(
    '/basic/product/updateProduct',
    data,
  );
}

/**
 * 获取商品列表
 */
export async function getProductList(params: {
  name?: string;
  pageNum: number;
  pageSize: number;
}) {
  return requestClient.get<productApi.getProductListResult>(
    '/basic/product/getProductPage',
    { params },
  );
}

/**
 * 根据ID获取商品详情
 */
export async function getProductById(productId: string) {
  return requestClient.get<productApi.getDetailResult>(
    `/basic/product/getProductDetails?productId=${productId}`,
  );
}

/**
 * 删除商品
 */
export async function deleteProduct(id: string) {
  return requestClient.post<productApi.baseResult>(
    `/basic/product/deleteProduct`,
    { id },
  );
}
/**
 * 批量设置可预约时间
 */
export async function addApptTimeSlotList(
  data: productApi.addApptTimeSlotListParams[],
) {
  return requestClient.post<productApi.baseResult>(
    `/basic/apptTimeSlot/addApptTimeSlotList`,
    { apptTimeSlotDTOList: data },
  );
}
/**
 * 获取可预约时间列表
 */
export async function getApptTimeSlotList() {
  return requestClient.get<productApi.getAllApptTimeSlotListResult>(`/basic/apptTimeSlot/getAllApptTimeSlotList`);
}
/**
 * 更新产品状态
 */
export async function updateProductStatus(id: string) {
  return requestClient.post<productApi.baseResult>(
    `/basic/product/updateProductState`,
    { id },
  );
}
